package com.java1412.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.java1412.entity.User;
import com.java1412.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author java1412
 * @since 2023-02-20 9:38
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @Value("${server.port}") // 读取application.yml中的配置信息，注入当前成员变量
    private String port; // 读取端口号

    @RequestMapping(value = "/hi")
    public String home(
            @RequestParam(value = "userName", required = false, defaultValue = "admin") String userName
    ) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userName", userName);
        User user = userService.getOne(queryWrapper);
        return "hi," + user.getId() + "======" + user.getUserName() + "======" + user.getPassword() +
                "=====" + user.getSex() + "=====" + user.getAge() + " ,i am from port:" + port;
    }
}
